import  api from '@/api/index.js';
import {redirect} from "react-router-dom";

export  default async  function articleNewAction({request}){
    const formData = await request.formData();

    const article = Object.fromEntries(formData);
    article.tags = article.tags.split(',')
    const response = await api.article.createArticle(article);
    if (response && response.status !== 1) {
        throw new Error(response.message);
    }
    const slug = response.data.slug;
    return  redirect(`/article/${slug}`)
}